package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.CategoryAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.CategoryUpdateNewDTO;
import cn.tedu.csmall.product.service.ICategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
@RequestMapping("/categories")
@Api(tags = "01.类别管理模块")
public class CategoryController {
   @Autowired
    private ICategoryService categoryService;
   @ApiOperation("添加类别")
   @ApiOperationSupport(order = 100)
   @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid CategoryAddNewDTO categoryAddNewDTO){
       log.debug("即将处理【添加类别】的请求……");
       log.debug("CategoryAddNewDTO={}",categoryAddNewDTO);
           categoryService.addNew(categoryAddNewDTO);
           return JsonResult.ok();

   }
   @ApiOperation("删除类别")
   @ApiOperationSupport(order = 200)
   @PostMapping("/{id:[0-9]+}/delete")
   @ApiImplicitParam(name = "id",value = "类别id",required = true,dataType = "long")
   public JsonResult<Void> delete(@PathVariable Long id){
       log.debug("即将处理【删除类别】的请求，id={}", id);
       categoryService.deleteById(id);
       return JsonResult.ok();
   }
   @ApiOperation("启用类别")
   @ApiOperationSupport(order = 300)
   @PostMapping("/{id:[0-9]+}/enable")
   @ApiImplicitParam(name = "id",value = "类别id",required = true,dataType = "long")
   public JsonResult<Void> setEnable(@PathVariable Long id){
       log.debug("即将处理【启用类别】的请求，id={}", id);
       categoryService.setEnable(id);
       return JsonResult.ok();
   }
    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 310)
    @PostMapping("/{id:[0-9]+}/disable")
    @ApiImplicitParam(name = "id",value = "类别id",required = true,dataType = "long")
    public JsonResult<Void> setDisable(@PathVariable Long id){
        log.debug("即将处理【禁用类别】的请求，id={}", id);
        categoryService.setDisable(id);
        return JsonResult.ok();
    }
    @ApiOperation("显示类别")
    @ApiOperationSupport(order = 400)
    @PostMapping("/{id:[0-9]+}/display")
    @ApiImplicitParam(name = "id",value = "类别id",required = true,dataType = "long")
    public JsonResult<Void> setDisplay(@PathVariable Long id){
        log.debug("即将处理【显示类别】的请求，id={}", id);
        categoryService.setDisplay(id);
        return JsonResult.ok();
    }
    @ApiOperation("隐藏类别")
    @ApiOperationSupport(order = 410)
    @PostMapping("/{id:[0-9]+}/hidden")
    @ApiImplicitParam(name = "id",value = "类别id" ,dataType = "long",required = true)
    public JsonResult<Void> setHidden(@PathVariable Long id){
        log.debug("即将处理【隐藏类别】的请求，id={}", id);
        categoryService.setHidden(id);
        return JsonResult.ok();
    }
    @ApiOperation("修改类别")
    @ApiOperationSupport(order = 500)
    @PostMapping("/update")
    public JsonResult<Void> update(@Valid CategoryUpdateNewDTO categoryUpdateNewDTO){
       log.debug("即将处理修改类别的请求,categoryUpdateNewDTO={}",categoryUpdateNewDTO);
       categoryService.update(categoryUpdateNewDTO);
       return JsonResult.ok();
    }
}
